home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / SoundSwirl 1.1 / src / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-04  |  2.8 KB  |  160 lines  |  [TEXT/CWIE]

  1. // SoundSwirl
  2. // version 1.1
  3. // updated for CW7 on 951215
  4.  
  5. /*
  6. ** main.c
  7. ** 
  8. ** Main control center for the application skeleton
  9. */
  10.  
  11. #include "main.h"        /* general application header */
  12.  
  13. static pascal void restartProc(void);
  14. static void Init(void);
  15. static void MakeWindows(void);
  16. static void SetupMenus(void);
  17.  
  18.  
  19. void main(void)
  20. {
  21.     EventRecord        theEvent;                /* the current event   */
  22.     int                eventMask = everyEvent;    /* current event mask  */
  23.     int                haveEvent;                /* do we have an event */
  24.     long            sleepTime = 0;            /* time to sleep/WNE   */
  25.     Boolean            weHaveWNE=0;            /* do we have MF or 7  */
  26.     
  27.     gMainWindow = NULL;
  28.  
  29.  
  30.     Init();
  31.     InitSound();
  32.     SetupMenus();
  33.     MakeWindows();
  34.     weHaveWNE = TrapAvailable( 0xA860);        /* WaitNextEvent() */
  35.  
  36.     /************* main event loop ****************/
  37.  
  38.     /* HideCursor();    /* */
  39.     while (1) {
  40.         if (weHaveWNE)
  41.         {
  42.             if (WaitNextEvent( eventMask, &theEvent, sleepTime, NULL))
  43.                 DoEvent(&theEvent);
  44.         }
  45.         else
  46.         {
  47.             SystemTask();
  48.             if ( GetNextEvent(eventMask, &theEvent) ) DoEvent(&theEvent);
  49.         }
  50.         
  51.         DrawStep();
  52.     } /* while */
  53. } /* main() */
  54.  
  55.  
  56. /***********************
  57. ** Init()
  58. **
  59. ** This initializes the toolbox
  60. ************************/
  61.  
  62. static void Init()
  63. {
  64.     register int i;
  65.     GrafPtr    windManPort;                /* window manager port */
  66.  
  67.     
  68.     InitGraf(&qd.thePort);
  69.     InitFonts();
  70.     InitWindows();
  71.     InitMenus();
  72.     TEInit();
  73.     InitDialogs(restartProc);        
  74.     InitCursor();
  75.     
  76.     FlushEvents(everyEvent, 0);
  77.  
  78.     for (i=0; i<6; i++) (void)MoreMasters();
  79.     
  80.     GetWMgrPort(&windManPort);
  81.     
  82.     SetPort(windManPort);
  83.     
  84.     SetEventMask(everyEvent);
  85. } /* Init() */
  86.  
  87.  
  88.  
  89. /**********************
  90. ** restartProc()
  91. **
  92. ** This is used for the system error/bomb dialog boxes.
  93. ** Just in case it crashes, we may have a way out.
  94. ***********************/
  95.  
  96. static pascal void restartProc(void)
  97. {
  98.     ExitToShell();
  99. } /* restartProc() */
  100.  
  101.  
  102.  
  103. /***********************
  104. ** SetupMenus()
  105. **
  106. ** loads the menubar and menus.  Adds DAs to apple menu.
  107. ************************/
  108. static void SetupMenus(void)
  109. {
  110.     Handle mbarH;
  111.     
  112.     mbarH = (Handle)GetNewMBar(MENU_BAR);
  113.     if (mbarH == NULL) {
  114.         SysBeep(1); SysBeep(1);
  115.         ExitToShell();
  116.     }
  117.     SetMenuBar( mbarH);
  118.     gAppleM= GetMHandle(APPLE_MENU);
  119.     AddResMenu( gAppleM, 'DRVR');
  120.     gFileM = GetMHandle(FILE_MENU);
  121.     gEditM = GetMHandle(EDIT_MENU);
  122.     gListenM = GetMHandle(LISTEN_MENU);
  123.  
  124.     DisableItem( gListenM, ListenStop);
  125.  
  126.     DrawMenuBar();
  127.     DisposHandle(mbarH);  /* don't need it anymore */
  128. } /* SetupMenus() */
  129.  
  130.  
  131.  
  132. static void MakeWindows(void)
  133. {
  134.     gMainWindow= GetNewWindow( MainWindID, NULL, (WindowPtr)-1L);
  135.     SelectWindow(gMainWindow);
  136.     SetPort( gMainWindow);
  137. } /* MakeWindows() */
  138.  
  139.  
  140. /****************************
  141. ** Cleanup()
  142. **
  143. ** The main program exiting procedure.  It cleans up after
  144. ** ourselves
  145. *****************************/
  146. void Cleanup(void)
  147. {
  148.     DoFileClose();    /* dostuff.c - dispose of any dynamic stuff */
  149.     KillSound();
  150.     ExitToShell();
  151. } /* Cleanup() */
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.